package com.d0317;

import java.util.Scanner;

public class StopWaitThread {
    public static void main(String[] args) {
        IOWaitThread stopWaitThread=new IOWaitThread();
        System.out.println("线程启动");
        stopWaitThread.start();
        //stopWaitThread.interrupt();
        stopWaitThread.scanner.close();//关闭底层资源后，线程
    }

}
class IOWaitThread extends Thread{
    Scanner scanner=new Scanner(System.in);
    private boolean flag=true;

    @Override
    public void run() {
        try{
        while(flag) {
            System.out.println("等待用户输入:");
            scanner.next();
           }
        }catch(Exception ex){
            System.out.println("线程中断");
        }
    }
    public void stopThread(){
        flag=false;
    }
}
